#pragma once
#include <string>
#include <map>
#include <ft2build.h>
#include FT_CACHE_H

#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/function.hpp>

namespace TrueText {

class Stream;

struct FaceId
{
	std::string id;
	boost::function<FT_Face ()> faceLoader;
private:
	FaceId();
	friend class FaceIdManager;
};

class FaceIdManager
{
public:
	FaceIdManager();
	~FaceIdManager();
	FaceId* GetFaceId(std::string id, boost::function<FT_Face ()> faceLoader);
	void RegisterStream(FT_Stream stream, boost::shared_ptr<Stream> ttStreamPtr);
	void ClosingStream(FT_Stream stream);
private:
	typedef std::map<std::string, FaceId*> FaceIdMap;
	FaceIdMap faceIdMap;
	typedef std::map<FT_Stream, boost::shared_ptr<Stream> > StreamMap;
	StreamMap streamMap;
};

void InitializeCache();
void ShutdownCache();

FaceIdManager* GetFaceIdManager();
FTC_Manager GetFtcManager();
FTC_CMapCache GetCMapCache();
FTC_ImageCache GetImageCache();

} // namespace TrueText